<template>
  <van-row class="main-menu">
    <van-nav-bar left-text="返回" :title="assessType === $vo.AssessType.CORP + '' ? '公司问题整改' : '单位问题整改'" @click-left="doBack"/>
    <van-row class="menu-content">
      <van-grid :column-num="3">
        <van-grid-item :to="'/rectify/list/' + assessType + '/' + $vo.RectStep.FIND">
          <van-icon slot="icon" class-prefix="cspg" name="score-query cspg-color-blue" size="48" />
          <van-row slot="text" class="grid-item-text">指定整改责任部门</van-row>
        </van-grid-item>
        <van-grid-item :to="'/rectify/list/' + assessType + '/' + $vo.RectStep.PLAN">
          <van-icon slot="icon" class-prefix="cspg" name="score-query cspg-color-blue" size="48" />
          <van-row slot="text" class="grid-item-text">整改措施制定</van-row>
        </van-grid-item>
        <van-grid-item :to="'/rectify/list/' + assessType + '/' + $vo.RectStep.APPR">
          <van-icon slot="icon" class-prefix="cspg" name="score-query cspg-color-blue" size="48" />
          <van-row slot="text" class="grid-item-text">整改措施审核</van-row>
        </van-grid-item>
        <van-grid-item :to="'/rectify/list/' + assessType + '/' + $vo.RectStep.EXEC">
          <van-icon slot="icon" class-prefix="cspg" name="score-query cspg-color-blue" size="48" />
          <van-row slot="text" class="grid-item-text">整改措施落实</van-row>
        </van-grid-item>
        <van-grid-item :to="'/rectify/list/' + assessType + '/' + $vo.RectStep.ACCE">
          <van-icon slot="icon" class-prefix="cspg" name="score-query cspg-color-blue" size="48" />
          <van-row slot="text" class="grid-item-text">整改成果验收</van-row>
        </van-grid-item>
      </van-grid>
    </van-row>

    <van-dialog style="width: 90%" v-model="showDialog" title="请选择操作部门" show-cancel-button @confirm="doSelectedDept" @cancel="$router.back()" :before-close="verifyOperate">
      <van-radio-group v-model="selectedDept">
        <van-cell-group style="margin-top: 20px" :border="false">
          <card-main-dept
            v-for="(depart) in deptList"
            :key="depart.department_path"
            :department="depart"
            @onClick="startSelectDept(depart)"/>
        </van-cell-group>
      </van-radio-group>
      <van-row style="font-size: 12px;color: red;text-align: center;height:30px; line-height: 30px">{{showError ? '请选择一个部门' : ''}}</van-row>
    </van-dialog>
  </van-row>
</template>

<script>
import CardMainDept from '@/views/common/card/CardMainDept'
export default {
  name: 'Index',
  components: { CardMainDept },
  props: ['assessType'],
  data () {
    return {
      showError: false,
      showDialog: false,
      deptList: [],
      selectedDept: null
    }
  },
  mounted () {
    if (!this.$store.state.authInfo.rectifyDept) {
      this.deptList = this.$store.state.authInfo.user.rectify
      if (this.deptList.length === 1) {
        this.$store.commit('authInfo/setRectifyDept', this.deptList[0])
      } else {
        this.showDialog = true
      }
    }
  },
  methods: {
    verifyOperate (action, done) {
      if (action === 'confirm' && !this.selectedDept) {
        this.showError = true
        done(false)
      } else {
        done()
      }
    },
    startSelectDept (depart) {
      this.showError = false
      this.selectedDept = depart
    },
    doSelectedDept () {
      if (this.selectedDept) {
        this.$store.commit('authInfo/setRectifyDept', this.selectedDept)
      }
    },
    doBack () {
      this.$store.commit('authInfo/delRectifyDept')
      this.$router.back()
    }
  }
}
</script>

<style scoped lang="less">
.main-menu{
  background-color: #F9F9F9;
  .menu-content {
    background-color: #FFFFFF;
    .grid-item-text{
      text-align: center;
      font-size: 14px;
      margin: 5px 0px;
    }
  }
}
</style>
